/*
 * ============================================================================
 *
 *       Filename:  devname.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2014年03月27日 08时52分36秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * ============================================================================
 */
#include <stdio.h>
#include <stdint.h>

#include <sys/ioctl.h>
#include <net/if.h>
#include <sys/socket.h>

void pr_mac(char *info)
{
	printf("mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
		(unsigned char) info[0],      
		(unsigned char) info[1],      
		(unsigned char) info[2],      
		(unsigned char) info[3],      
		(unsigned char) info[4],      
		(unsigned char) info[5]);     
}
int main()
{
	int sock = socket(AF_INET, SOCK_DGRAM, 0);

	int i = 1;
	struct ifreq req;
	while(1) {
		req.ifr_name[0] = '\0';
		req.ifr_ifindex = i++;
		ioctl(sock, SIOCGIFNAME, &req);
		if(req.ifr_name[0] == '\0')
			break;
		printf("name:%s\n", req.ifr_name);
		ioctl(sock, SIOCGIFHWADDR, &req);
		pr_mac(req.ifr_hwaddr.sa_data);
	}
}
